<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return['role']=$_SESSION['role'];
if($_RQ['op']=='list'){
	cfc('core')->checklogin();
	$pindex = max(1, intval($_RQ['page']));
	$psize = 15;
	$params=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']);
    $orderby='createtime desc';
	$total='';
	if(isset($_RQ['status'])){
		$params['status']=intval($_RQ['status']);
		$return['status']=$_RQ['status'];
	}
	$return['list']=pdo_getslice('jy_kaoshi_card',$params,array($pindex,$psize),$total,$fields,'',$orderby);	
	foreach($return['list'] as &$v){
			$v['createtime']=date('Y-m-d H:m:s',$v['createtime']);
			$v['statustitle']=$this->card_status[$v['status']];
	}
	$return['post']=array();
	if($_RQ['zu_id']){
		$tizu=pdo_get('jy_kaoshi_tiku_zu',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['zu_id']));
		$card=pdo_get('jy_kaoshi_card',array('status'=>1,'mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
		$tizu['codenumber']=$card['codenumber'];
		$tizu['cardid']=$card['id'];
		$tizu['cardid']=$card['id'];
		$return['showbang']=true;
		$return['tizu']=$tizu;
	}
	exi($return);
}
if($_RQ['op']=='get'){
	$this->model('model')->check_set();
	$post=get_postdata();
	$codepassword=$post['codepassword'];
	$codenumber=$post['codenumber'];
	if(!$codenumber || !$codepassword){
		exi('请卡号和密码！','error');
	}
	$card=pdo_get('jy_kaoshi_card',array('codepassword'=>$codepassword,'codenumber'=>$codenumber,'uniacid'=>$_SESSION['uniacid']));
	if(!$card['id']){
		exi('卡号或密码不正确，领卡失败！','error');
	}
	if($card['status'] || $card['mid']){
		exi('该答题卡已被领取！','error');
	}
	pdo_update('jy_kaoshi_card',array('mid'=>$_SESSION['uid'],'status'=>1),array('id'=>$card['id'],'uniacid'=>$_SESSION['uniacid']));
	exi('领取答题卡成功！');
}
if($_RQ['op']=='tizu'){
	$this->model('model')->check_set();
	$post=get_postdata();
	$zu_id=$post['id'];
	$cardid=$post['cardid'];
	if(!$cardid){
		exi('请选择答题卡！','error');
	}
	if(!$zu_id){
		exi('请选择题库！','error');
	}
	$card=pdo_get('jy_kaoshi_card',array('id'=>$cardid,'uniacid'=>$_SESSION['uniacid']));
	if(!$card['id']){
		exi('答题卡不存在！','error');
	}
	if($card['zu_id']){
		exi('该答题卡已绑定题库！','error');
	}
	pdo_update('jy_kaoshi_card',array('zu_id'=>$zu_id,'status'=>2,'gettime'=>time()),array('id'=>$card['id'],'uniacid'=>$_SESSION['uniacid']));
	exi('答题卡绑定题库成功！','','/ti_index//id='.$zu_id);
}